package main

import (
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/registry"
	"github.com/micro/go-micro/web"
	"github.com/micro/go-plugins/broker/grpc"
	"github.com/micro/go-plugins/registry/consul"
	_ "github.com/micro/go-plugins/registry/etcdv3"
	"goMicro/day05/client/services"
	"goMicro/day05/client/weblib"
	"goMicro/day05/client/wrappers"
)

func main() {
	//注册 consul
	register := consul.NewRegistry(
		registry.Addrs("127.0.0.1:8500"),
	)
	//注册 etcd
	//register := etcdv3.NewRegistry(
	//	registry.Addrs("127.0.0.1:2379"),
	//)
	grpcBroker := grpc.NewBroker()
	microServer := micro.NewService(
		micro.Name("prodservice.client"),
		micro.WrapClient(wrappers.NewLogWrapper),
		micro.WrapClient(wrappers.NewProdWrapper),
		micro.Registry(register),
		micro.Broker(grpcBroker),
	)
	microServer.Init()
	// 后端服务名，客户端
	prodServer := services.NewProdService("prodService", microServer.Client())
	httpServer := web.NewService(
		web.Name("httpProdService"),                  // 服务名
		web.Address(":8001"),                         //端口
		web.Handler(weblib.NewGinRouter(prodServer)), //处理器
	)
	httpServer.Run()
}
